package com.generalbackend.common.service.impl;

import com.generalbackend.common.constants.Constants;
import com.generalbackend.common.model.entity.CommonConfig;
import com.generalbackend.common.model.query.UpdateLoginBackgroundPictureQuery;
import com.generalbackend.common.service.CommonConfigService;
import com.generalbackend.common.service.ISystemConfigurationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author tim.xie
 * @date 2022/7/12 15:41
 */
@Slf4j
@Service
public class SystemConfigurationServiceImpl implements ISystemConfigurationService {

    @Autowired
    private CommonConfigService commonConfigService;

    @Override
    public String getLoginBackgroundPicture() {
        CommonConfig config = commonConfigService.getConfigByPrefixAndKey(Constants.SYSTEM_CONFIG_PREFIX, Constants.LOGIN_BACKGROUND_PIC_KEY);
        return config.getConfigValue();
    }

    @Override
    public boolean updateLoginBackgroundPicture(UpdateLoginBackgroundPictureQuery updateLoginBackgroundPictureQuery) {
        commonConfigService.updateConfigValueByPrefixAndKey(Constants.SYSTEM_CONFIG_PREFIX, Constants.LOGIN_BACKGROUND_PIC_KEY, updateLoginBackgroundPictureQuery.getUrl());
        return true;
    }
}
